package com.tc.quartz.server.job;

import org.quartz.JobExecutionContext;

import java.util.Map;

/**
 * 测试job
 * @author yongjin.ye
 *
 */
public class TestJob extends DisallowConcurrentProxyJob{

	@Override
	public Object doExecute(JobExecutionContext context) throws Exception {
		
		log.info("---------TestJob 运行开始----------");
		
		//log.info(QrtzUtil.obj2json(context.getMergedJobDataMap(), context.getJobDetail().getJobDataMap(), context.getTrigger().getJobDataMap()));
		
		/*int sleep = context.getJobDetail().getJobDataMap().getInt("sleep");
		int forCount = context.getJobDetail().getJobDataMap().getInt("forCount");
		
		sleep = sleep > 1000 * 60 ? 1000 * 60 : sleep;
		forCount = forCount > 1000 ? 1000 : forCount;
		
		for (int i = 0; i < forCount; i++) {
			Thread.sleep(sleep);
			log.info("TestJob运行日志==" + i);
		}*/
		
		for (int i = 0; i < 5; i++) {
			log.info("TestJob Thread.sleep(1000)...");
			Thread.sleep(1000L);
		}
		
		context.getTrigger().getJobDataMap().put("accountingDate", "20121212");
		
		log.info("TestJob 运行结束...");
		log.info(" --------TestJob 运行开始----------");
		
		this.jobRunLog.append("运行完成SUCCESS");
		
		return 111;
	}
	
	
	public interface TriggerJobDemoService {
		
		/**
		 * 退款job
		 * @param jobDataMap 可持久化和的job信息
		 * @param triggerData 手动触发的job信息
		 * @return String 返回结果可用在任务控制台查看
		 */
		public String refundJob(Map<?, ?> jobDataMap, Map<?, ?> triggerData);
		
		/**
		 * 退款job
		 * @param jobDataMap: (jobDataMap+triggerData合并后的data)
		 * @return String 返回结果可用在任务控制台查看
		 */
		public String refundJob(Map<?, ?> jobDataMap);
		
		/**
		 * 退款job
		 * @return String 返回结果可用在任务控制台查看
		 */
		public String refundJob();
				
		
	}

}
